package data
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import util.BitmapLoader;

	public class PhotoReceiver extends EventDispatcher
	{
		private var _dataLoader:URLLoader = new URLLoader();
		
		public function PhotoReceiver(target:IEventDispatcher=null)
		{
			super(target);
			
		}
		
		var kkk;
		public function search(key:String):void
		{
			kkk = key;
			_dataLoader.load(APIRequest.createRequest(key));
			_dataLoader.addEventListener(Event.COMPLETE, loadAPIDataComplete);
			
		}
		
		public var dnImage:BitmapLoader = new BitmapLoader();
		private function loadAPIDataComplete(e:Event):void
		{
			var resultImageMetaData = new XML(e.target.data);
			
			try{
				var imgurl = resultImageMetaData.channel.item[0].image.toString();
				trace(resultImageMetaData);
				trace(resultImageMetaData.channel.item.length());
			
				dnImage.load(new URLRequest(imgurl));
				this.dispatchEvent(new Event(Event.COMPLETE) );
				
			}catch(e:Error){
				_dataLoader.load(APIRequest.createRequest(kkk, "image"));
				_dataLoader.addEventListener(Event.COMPLETE, loadAPIDataComplete);
			}
			
			
			
		}
		
		
		
	}
}

/*
<rss version="2.0">
  <channel>
    <title>Naver Open API - image ::'???'</title>
    <link>http://search.naver.com</link>
    <description>Naver Search Result</description>
    <lastBuildDate>Wed, 25 Nov 2009 21:58:22 +0900</lastBuildDate>
    <total>2172</total>
    <start>1</start>
    <display>10</display>
    <item>
      <title>???·???·???, NSS ?? ?? ??</title>
      <link>http://openapi.naver.com/l?AAAC2MQQ6DIBRET/NZmg9ahAULqvYajWl/kSYopdjG2xdNk8nMm1lM3iIZH0ZHbPV3o1qU7LVS2gwMFs4aFMLQg6pBdzvoHmzHpkQPM+UcobYgLkU+uJm+72oeP5Sq2xKOrdyW5LwtLhD1UXaT/4FzLlGLU4OFmiuvntH9AFGKZhiTAAAA</link>
      <thumbnail>http://imgnews.naver.com/image/thumb120/117/2009/11/16/2047327.jpg</thumbnail>
      <sizeheight>249</sizeheight>
      <sizewidth>500</sizewidth>
    </item>
    <item>
      <title>???·???·???, ??? ??? ???</title>
      <link>http://openapi.naver.com/l?AAADWMTQ7CIBCFTzMsyUyxFRYssK3XMI0ixYQWkWp6e8HE5OV7P4uX92i1D5OzbPM3LY/Ysedm065hNHBSIBHGAaQA1degBjA9m5O96znnCMJAcy7ywS328+LL9LaJX9fw28ptcUJZ2CCqWqjiPxCRREkoOtEeVHsh/ojuC3try2iUAAAA</link>
      <thumbnail>http://imgnews.naver.com/image/thumb120/108/2009/11/18/2007607.jpg</thumbnail>
      <sizeheight>292</sizeheight>
      <sizewidth>500</sizewidth>
    </item>
    <item>
      <title>'????' ??? &amp;quot;??? ?? ??&amp;quot; ??</title>
      <link>http://openapi.naver.com/l?AAAB2Myw7CIBREv+ayJJc2KbBggX38hql6pZjQItKa/r1gMjlzMovJZyTjw+yI7f5hlMSOvXdKp4HRwkWDQhgHUC3ovooewPZsSfQ0S84RWgvNVOKDW+n74et8UOL3Lfy3clsaZVfYIOpSQlRU07cspRB4FfwV3Q/HvWh9iQAAAA==</link>
      <thumbnail>http://imgnews.naver.com/image/thumb120/076/2009/11/19/2012136.jpg</thumbnail>
      <sizeheight>282</sizeheight>
      <sizewidth>500</sizewidth>
    </item>
    <item>
      <title>??? &amp;quot;???? '?? ? ???' ??? ???&amp;quot;</title>
      <link>http://openapi.naver.com/l?AAAC2MzQ7CIBCEn2Y5ErZt+DlwwLa+hml0pZhQEammby9tTCYz38xhypbIhjh5Ymu4Wa2EZK+V8mZhdHAyoAWMA+gWTL+DGcD1bM50t3MpCVoHzbkqRL/Q982X6UOZX5/x2OptTURVvRHCHGU3+R8QUWLXqVZX0hfkj+R/j/Vl25MAAAA=</link>
      <thumbnail>http://imgnews.naver.com/image/thumb120/117/2009/11/16/2047385.jpg</thumbnail>
      <sizeheight>480</sizeheight>
      <sizewidth>320</sizewidth>
    </item>
    <item>
      <title>'????' ??? ???, NSS ?? ???? ??</title>
      <link>http://openapi.naver.com/l?AAAB2MQQ6DIBRET/NZEr4mAgsWVO01Gm1/kSZYpNjG2wtNJm8mbzH5iGR8mByx3T+MkqJj207pMDBauGhQAsYBVAu6r0MPYHu2JHqaJecIrYXmWuKDW+n34ev0pcTv7/B35ba0kF1hI4QuhVhRhZ43KRHxhvwV3QkLZcO1iQAAAA==</link>
      <thumbnail>http://imgnews.naver.com/image/thumb120/076/2009/11/16/2011651.jpg</thumbnail>
      <sizeheight>250</sizeheight>
      <sizewidth>500</sizewidth>
    </item>
    <item>
      <title>??? ???? ????…??? ? 13? ???? ??</title>
      <link>http://openapi.naver.com/l?AAADVMyw7CIBD8muVIdqla9sAB2/obplGkNaFFpJr+vdRoZjKvw+Q1OjOG3juxjFejazyIx+LSaqCzcGTQCF0LugJutsAt2EYMyd3MkHOEyoI6FY7BT+79lFP/ckle5vDdym1xpH1RhcjFiDbh30BETKrg/G9Iu5rkPfoPP7p1d5oAAAA=</link>
      <thumbnail>http://imgnews.naver.com/image/thumb120/015/2009/11/19/2160039.jpg</thumbnail>
      <sizeheight>126</sizeheight>
      <sizewidth>239</sizewidth>
    </item>
    <item>
      <title>'????', ??? ?? ??? ??? ?? ??</title>
      <link>http://openapi.naver.com/l?AAAC2MQQ7CIBRET/NZEj4kwl+wwLZewzSKFBMqRarp7aWNyWTmzSymbtnbmMbg2Rrv1mhxYsvqy2ZhcHAmMAKGHowC6nagHlzHpuIfdqo1g3IgL00xhdl/33weP77w2ysdW7ttiaibSyHoKLvRf0BEQoVG6kbyivyZww9Ejr6AkwAAAA==</link>
      <thumbnail>http://imgnews.naver.com/image/thumb120/117/2009/11/19/2047794.jpg</thumbnail>
      <sizeheight>281</sizeheight>
      <sizewidth>500</sizewidth>
    </item>
    <item>
      <title>'????' ???-???, ???? ??? ??</title>
      <link>http://openapi.naver.com/l?AAAB2MwQ6DIBBEv2Y5mgUrZQ8crNr/oLqoTVRKsY1/X2wyeW8yh0lHYDsvbmSxz4M1V9TitXM8LHQ13AgMQteCKYGas1ALdSOmyN5OKQUoa1D3nHkZV/6+i9V9OBb9tvy3fJuNsspUiJQl5QlzQnvqvZJKSm1ocE5XxEikHiV5P1yKZxh/nf5RqZ8AAAA=</link>
      <thumbnail>http://imgnews.naver.com/image/thumb120/015/2009/11/18/2159150.jpg</thumbnail>
      <sizeheight>333</sizeheight>
      <sizewidth>450</sizewidth>
    </item>
    <item>
      <title>NSS ?? ID?? ??! ???·???·??? ?</title>
      <link>http://openapi.naver.com/l?AAAC2MSw7CIBRFV/MYEj6WPgYMsK3bMI0ixYSKSDXdvWBMbs79DG7ZkzMhzt6RLVwN9kyR5+bybmCycNSADKYRUIIeWtAj2IEs2d3MUkoCaUGcqkL0q/u86Dq/XaaXR/xt9bY6Z1gpGNOt8Ab1HzjniqHEjks89N1Z0HvyX24WLaaUAAAA</link>
      <thumbnail>http://imgnews.naver.com/image/thumb120/108/2009/11/16/2007193.jpg</thumbnail>
      <sizeheight>249</sizeheight>
      <sizewidth>500</sizewidth>
    </item>
    <item>
      <title>[???] '????' ???? ??? ???</title>
      <link>http://openapi.naver.com/l?AAAC2MwQ7CIBBEv2Y5kqVECwcO2Nb/ILpSTKiIVNO/d2ucTOZN5jBtK+RSDpHEmq7O9HgUz5Xq5mDycLJgEKYRjAY77MWO4AcxV7q5ubUC2kN3ZqccF/q85BLeVOXlkX8b3zKx15wdomUotQf+B8WigHiQ9xK/6ZqQkIwAAAA=</link>
      <thumbnail>http://imgnews.naver.com/image/thumb120/073/2009/11/10/2010387.jpg</thumbnail>
      <sizeheight>400</sizeheight>
      <sizewidth>300</sizewidth>
    </item>
  </channel>
</rss>
[SWF] Users:SILVERGENE:Documents:Flex Builder 3:OpenSocialTestProject:bin-debug:OpenSocialTestProject.swf - 5,017 bytes after decompression

*/